package com.asiainfo.ssm.execute.dao.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.asiainfo.commons.util.DateTimeUtil;
import com.asiainfo.ssm.execute.bo.BOExecSmsRecordEngine;
import com.asiainfo.ssm.execute.dao.interfaces.IExecSmsRecordDAO;
import com.asiainfo.ssm.execute.ivalues.IBOExecSmsRecordValue;
import com.asiainfo.ssm.execute.service.impl.KafkaOrderSmsRecordProcessSVImpl;

public class ExecSmsRecordDAOImpl implements IExecSmsRecordDAO {

	private transient Log log = LogFactory.getLog(ExecSmsRecordDAOImpl.class);

	@Override
	public IBOExecSmsRecordValue getExecSmsRecord(String billId) throws Exception {
		return BOExecSmsRecordEngine.getBean(billId);
	}

	@Override
	public void saveExecSmsRecord(IBOExecSmsRecordValue smsRecord) throws Exception {
		BOExecSmsRecordEngine.save(smsRecord);
	}

	@Override
	public void saveExecSmsRecord(IBOExecSmsRecordValue[] aBeans) throws Exception {

		for (IBOExecSmsRecordValue smsRecord : aBeans) {
			try {
				IBOExecSmsRecordValue smsRcordFDB = getExecSmsRecord(smsRecord.getBillId());
				if (!smsRcordFDB.isNew()) {
					smsRcordFDB.setActId(smsRecord.getActId());
					smsRcordFDB.setLatestExecDate(smsRecord.getLatestExecDate());
					smsRcordFDB.setDayExecTimes(smsRecord.getDayExecTimes());
					smsRcordFDB.setMonthExecTimes(smsRecord.getMonthExecTimes());
					BOExecSmsRecordEngine.save(smsRcordFDB);
				} else {
					BOExecSmsRecordEngine.save(smsRecord);
				}
			} catch (Exception e) {
				log.error("ExecSmsRecordDAOImpl", e);
				e.printStackTrace();
			}
		}

	}

}
